import { post, get, put, del } from "@/utils/NetworkRequest/index";
import { objToQueryString } from '@/utils/Tools/ObjectToCharacter';
//权限数据
export const userSystemPermissionApi = (page = 1, query = {}, size = 10) => {
    if ('page' in query) {
        delete query.page
    }
    if ('pageSize' in query) {
        delete query.pageSize
    }
    query = objToQueryString(query)
    return get<any>(`/api/system/permission?page=${page}&pageSize=${size}${query}`)
}

// 编辑

export const userSystemIditApi = (editData: any) => {
    return post<any>(`/api/customer/system/edit`, editData)
}
//编辑数据
export const userSystemPermissionSaveApi = (level: string) => {
    return get<any>(`/api/system/permission/edit?level=${level}`)
}

// 保存
export const userSystemSaveApi = (promissionData: object) => {
    return post<any>(`/api/customer/system/save`, promissionData)
}


// log
export const userSystemLogitApi = (page = 1, query = {}, size = 10) => {
    if ('page' in query) {
        delete query.page
    }
    if ('pageSize' in query) {
        delete query.pageSize
    }
    query = objToQueryString(query)
    return get<any>(`/api/system/log?page=${page}&pageSize=${size}${query}`)
}
// log回显删除

export const userSystemLogEditApi = (logIp: string) => {
    return get<any>(`/api/customer/system/logedit?logIp=${logIp}`)
}








/**
 * 用户添加
 * @param {object} userData  添加用户表单项数据
 * @returns Promise<number>
 */
export const userAddApi = (userData: IUserModule.IUserAddForm) => {
    return post<number>('/api/user/add', userData)
}


// 用户列表数据
export const userListApi = (page = 1, query = {}, size = 10) => {
    if ('page' in query) {
        delete query.page
    }
    query = objToQueryString(query)
    return get<IUserModule.IUserList>(`/api/user/list?page=${page}&size=${size}${query}`)

}
//批量删除
export const userDeleteApi = (userId: number[]) => {
    console.log({ userId })
    return post<number>('/api/user/delete', { userId })
}

// 上传图片
export const uploadAvatarApi = (formData: FormData) => {
    return post<IUserModule.IUpdateAvatar>('/api/user/uploadAvatar', formData)
}


// 删除上传图片
export const deleteuploadAvatarApi = (path: string) => {
    return post<number>('/api/user/deleteuploadAvatar', { path })
}

// // 根据用户id返回用户记录
export const getUidToInfoApi = (id: number) => {
    return get<any>(`/api/user/${id}`)
}

// // 根据用户id修改对应用户记录
// export const editUserToInfoApi = (id: number, userData: IUserModule.IUserInfo) => {
//     return put<number>(`/api/user/${id}`, userData)
// }
